var express = require('express');
var router = express.Router();
//引入用户名业务层
let  userService= require('../src/service/userService')

//登录路径
router.get("/login/:username/:pwd",async(req,res)=>{
  //获得客户端的参数
   let {username,pwd} = req.params;
   let result = await userService.login(username,pwd);
 
   //console.log(result,'==>>')
     if(result){
      res.json({code:0,msg:"登录成功"})
   }else{
    res.json({code:1,msg:"用户名或者密码错误"})
   }  
})

//添加用户
router.post('/adduser',async (req,res)=>{
    //获取客户端参数
    let {username,pwd} = req.body;
    
     let result = await userService.addUser(username,pwd);
     if(result){
       res.json({code:0,msg:"添加成功"});
     }else{
      res.json({code:1,msg:"添加失败,用户名已被注册"});
     }
})


module.exports = router;
